<?php
$this->breadcrumbs = array(
    '主题管理'
);
?>
<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'search-form',
    'type' => 'search',
    'method' => 'GET',
    'htmlOptions' => array('class' => 'navbar-search pull-left', 'style' => 'margin:0;width:100%;'),
));
if ($form instanceof TbActiveForm) {

}
?>
<div class="submenu">
    <div class="row">
        <div class="col-xs-4">
            <?php
            echo $form->dropDownList($model, 'sid', Series::getOptions('series', array('' => '===关联类目===')), array('class' => 'form-control', 'data-select' => 'picker', 'data-live-search' => 'true'));
            ?>
        </div>
        <div class="col-xs-6">
            <?php
            echo $form->textFieldRow($model, 'searchKey');
            ?>
        </div>
        <div class="col-xs-1">
            <button class="btn btn-primary" style="width:100%;" type="submit" name="yt0"><i class="fa fa-search"></i>
            </button>
        </div>

        <div class="col-xs-1">
            <?php
            $this->widget('bootstrap.widgets.TbButton', array(
                'label' => '新增',
                'htmlOptions' => array('class' => 'pull-right btn-success', 'style' => 'width:100%'),
                'url' => $this->createUrl('create', ['type' => 'channel']),
            ));
            ?>
        </div>
    </div>
</div>
<?php
$this->endWidget();
?>
<div>
    <?php
    $columns = array(
        array('name' => 'name', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'headerHtmlOptions' => array('style' => 'width:10%')),
        array('header' => '缩略图', 'name' => 'thumbnail', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'headerHtmlOptions' => array('style' => 'width:20%')),
        array('header' => '相关类目', 'name' => 'link', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'headerHtmlOptions' => array('style' => 'width:30%')),
        array('header' => '操作', 'name' => 'operations', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'headerHtmlOptions' => array('style' => 'width:20%')),
    );
    $this->widget('bootstrap.widgets.TbGridView', array(
        'id' => 'model-grid',
        'ajaxVar' => null,
        'type' => array(),
        'enableSorting' => true,
        'dataProvider' => $model->searchByKey(),
        'columns' => $columns,
    ));
    ?>
</div>

<script type="text/javascript">
    $(function ($) {
        $(document).on('click', 'a.delete', function () {
            if (!confirm('确定删除?')) return false;
            var th = this;
            var afterDelete = function () {
            };
            var type = $(this).attr('type');
            var id = '';
            $.fn.yiiGridView.update('model-grid', {
                type: 'GET',
                url: $(this).attr('href'),
                ajaxUpdate: false,
                success: function (data) {
                    if (data == 'Success') {
                        $.fn.yiiGridView.update('model-grid');
                        alert('success');
                    } else {
                        alert(data);
                    }
                    afterDelete(th, true, data);
                },
                error: function (XHR) {
                    return afterDelete(th, false, XHR);
                }
            });
            return false;
        });
    });
</script>
